<?php
class MyZend_View_Helper_MySelectBox extends Zend_View_Helper_Abstract {
	public function mySelectBOx($name, $value = null, $options, $attribs = array() ) {
		//print_r($options);
		$strAttribs = '';
		
		// if isset attribs
		if(count($attribs) > 0) {
			foreach ($attribs as $keyAttribs => $valueAttribs) {
				$strAttribs .= $keyAttribs. '="' . $valueAttribs . '" ';
			}
			
		}
		
		$xhtml = '<select name = "' . $name . '" id = "' . $name . '" ' . $strAttribs . ' >';
		
		foreach ($options as $key => $info) {
			$strSelect = '';
			
			// if selected default
			if($info['id'] == $value){
				$strSelect = 'selected="selected"';
			}
			
			// if check lever options
			if($info['level'] == 1){
				$xhtml .= '<option value="' . $info['id'] . '" ' . $strSelect . '>' . $info['name'] . '</option>';
			}else {
				$string = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				$newString = '';
				for($i=1;$i<$info['level']; $i++){
					$newString .= $string;
				}
				$info['name'] = $newString . $info['name'];
				$xhtml .= '<option value="' . $info['id'] . '" ' . $strSelect . '>' . $info['name'] . '</option>';
			}
		}
		
		$xhtml .= '</select>';
		return $xhtml;
		
	}
}